package com.libui.thirdpartsdk.systemsdk

import android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import android.net.Uri
import com.libui.BaseApplication
import com.libui.thirdpartsdk.SDKInterface
import com.libui.thirdpartsdk.share.ShareCompletion
import com.libui.thirdpartsdk.share.ShareInterface
import com.libui.thirdpartsdk.share.models.ShareObjectType
import com.libui.thirdpartsdk.share.models.ShareUrlObject


class BrowserShare : ShareInterface {
    companion object {
        val builder = object : ShareInterface.Builder {
            override val type: String = "browser"

            override val title: String = "浏览器"

            override val icon: String? = "browser.png"

            override val selectedIcon: String? = null

            override fun build(sdk: SDKInterface): ShareInterface {
                return BrowserShare()
            }
        }
    }

    override val shareObjectTypes: List<ShareObjectType> = listOf(ShareObjectType.URL)

    override val type: String
        get() = builder.type

    override val title: String
        get() = builder.title

    override val icon: String?
        get() = builder.icon

    override val selectedIcon: String?
        get() = builder.selectedIcon

    override var isSelected: Boolean = false

    override fun shareUrl(shareObject: ShareUrlObject, completion: ShareCompletion?) {
        val uri = Uri.parse(shareObject.url)
        val intent = Intent(Intent.ACTION_VIEW, uri)
        intent.flags = FLAG_ACTIVITY_NEW_TASK
        BaseApplication.instance?.startActivity(intent)

        completion?.let { it(true) }
    }
}